<template>
	<view>
		<navbar title="绑定银行卡" :autoBack="true"></navbar>
		<view class="con">
			<view class="con__box">
				<image src="/static/daikuan/card.png" class="con__box__card" mode=""></image>
				<view class="con__box__a">
					添加银行卡
				</view>
				<view class="con__box__b">
					请绑定持卡人本人的银行卡
				</view>
				<view class="con__box__form">
					<view class="con__box__form__item">
						<view class="con__box__form__item__label">
							真实姓名
						</view>
						<input type="text" class="con__box__form__item__inp" v-model="form.name" placeholder="请输入真实姓名" />
					</view>
					<view class="con__box__form__item">
						<view class="con__box__form__item__label">
							卡号
						</view>
						<input type="text" class="con__box__form__item__inp" v-model="form.cardno" placeholder="请输入卡号" />
					</view>
					<view class="con__box__form__item">
						<view class="con__box__form__item__label">
							卡类型
						</view>
						<input type="text" class="con__box__form__item__inp" v-model="form.cardtype" placeholder="请输入卡类型" />
					</view>
				</view>
				<view class="con__box__c">
					<u-button color="#3262FD" :loading="loading" @click="submit" text="确认"
						:customStyle='{width:"628rpx",height:"94rpx",margin:0,padding:0,borderRadius:"15rpx",fontSize:"32rpx"}'></u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import user from '@/api/_user.js'
	export default {
		data() {
			return {
				form: {
					name: '',
					cardno: '',
					cardtype: ''
				},
				loading: false,
				id:null
			};
		},
		methods: {
			async submit() {
				let {
					name,
					cardno,
					cardtype
				} = this.form
				if (!name) {
					uni.$u.toast('请填写真实姓名')
					return
				}
				if (!cardno) {
					uni.$u.toast('请填写卡号')
					return
				}
				if (!cardtype) {
					uni.$u.toast('请填写卡类型')
					return
				}
				let _this=this
				this.loading=true
				if(this.id){//修改
					let res = await user.editBank(this.form)
					if (res.data.code == 1) {
						uni.$u.toast('修改成功')
						setTimeout(()=>{
							_this.loading=false
							uni.navigateBack()
						},1000)
					}else{
						_this.loading=false
					}
				}else{
					let res = await user.bindCard(this.form)
					if (res.data.code == 1) {
						uni.$u.toast('绑定成功')
						setTimeout(()=>{
							_this.loading=false
							uni.navigateBack()
						},1000)
					}else{
						_this.loading=false
					}
				}
				
			},
			async getbank(){
				let res = await user.getMyBank()
				if(res.data.code==1){
					if(res.data.data){
						this.form=res.data.data
						this.id=res.data.data.id
					}
				}
			}
		},
		onLoad() {
			this.getbank()
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f8f8f8;
	}

	.con {
		padding: 20rpx 30rpx;

		&__box {
			background: #FFFFFF;
			border-radius: 20rpx;

			&__card {
				width: 218rpx;
				height: 167rpx;
				margin: 105rpx 0 76rpx 235rpx;
			}

			&__a {
				font-family: PingFang SC;
				font-weight: 800;
				font-size: 36rpx;
				color: #1E1E1E;
				line-height: 36rpx;
				text-align: center;
				margin-bottom: 39rpx;
			}

			&__b {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 29rpx;
				color: #6D6D6D;
				line-height: 29rpx;
				text-align: center;
				margin-bottom: 40rpx;
			}

			&__form {
				padding-left: 32rpx;

				&__item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					height: 106rpx;
					border-bottom: 2rpx solid #F9F9F9;
					padding-right: 34rpx;

					&__label {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: #6D6D6D;
						line-height: 38rpx;
					}

					&__inp {
						text-align: right;
						font-family: PingFang SC;
						font-weight: bold;
						font-size: 26rpx;
						color: #020202;
						line-height: 38rpx;
					}
				}
			}

			&__c {
				padding: 50rpx 30rpx 60rpx 30rpx;

				&__t {
					padding-left: 10rpx;
					font-family: PingFang SC;
					font-weight: bold;
					font-size: 21rpx;
					color: #8A8B94;
					line-height: 21rpx;
					margin-bottom: 60rpx;
				}

			}
		}
	}
</style>